package pattern2;

/**
 * @author wdl
 */
abstract class CashSuper {
    /**
     * 现金收取的抽象类
     *
     * @param money 现金原价
     * @return 放回当前的具体价格
     */
    public abstract double acceptCash(double money);
}

/**
 * 正常收取价格
 */
class CashNormal extends CashSuper {

    @Override
    public double acceptCash(double money) {
        return money;
    }
}

/**
 * 商品打折的价格
 */
class CashRate extends CashSuper {
    /**
     * 折扣率
     */
    private double moneyRate;

    /**
     * 构造方法
     * @param moneyRate 传入折扣率
     */
    public CashRate(double moneyRate) {
        this.moneyRate = moneyRate;
    }

    @Override
    public double acceptCash(double money) {
        return money * moneyRate;
    }
}

/**
 *
 */

class CashReturn extends CashSuper {
    /**
     * 返现条件与返现金额
     */
    private double moneyCondition;
    private double moneyReturn;

    /**
     * 构造函数
     * @param moneyCondition 返现条件满多少
     * @param moneyReturn 返现金额返多少
     */
    public CashReturn(double moneyCondition, double moneyReturn) {
        this.moneyCondition = moneyCondition;
        this.moneyReturn = moneyReturn;
    }

    @Override
    public double acceptCash(double money) {
        //如果大于返现的价格则返回扣除返现的现金
        if (money >= moneyCondition) {
            return money - moneyReturn;
        }
        return money;
    }
}
